package pers.dzk.fivelnarow.piece;

import javax.swing.*;
import java.awt.*;
import java.io.Serializable;

/**
 * @author 丁泽凯
 * 棋子
 */
public abstract class Piece implements Serializable {
    private int size = 45;
    private Point point;
    private PieceType code;
    private ImageIcon image;
    private Point offset;
    public Piece(){
        setOffset(new Point(-size/2, -size/2));
    }
    public Piece(ImageIcon img,Point offset,PieceType code){
        this.image = img;
        this.offset = offset;
        this.code = code;
    }
    public Point getPrintPoint() {
        return new Point(point.x+offset.x, point.y+offset.y);
    }

    public Point getOffset() {
        return offset;
    }

    public void setOffset(Point offset) {
        this.offset = offset;
    }

    public ImageIcon getImage() {
        return image;
    }

    public void setImage(ImageIcon image) {
        this.image = image;
    }

    public Point getPoint() {
        return new Point(point.x, point.y);
    }

    public void setPoint(Point point) {
        this.point = point;
    }

    public PieceType getCode() {
        return code;
    }

    public void setCode(PieceType code) {
        this.code = code;
    }

    public void paint(Graphics2D g){
        if(image == null){
            if(code == PieceType.黑棋){
                g.setColor(Color.black);
            }else{
                g.setColor(Color.white);
            }
            g.fillOval(getPrintPoint().x,getPrintPoint().y,size,size);
            return;
        }
        image.paintIcon(null,g,getPrintPoint().x,getPrintPoint().y);
    }

}
